home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 22
/
Cream of the Crop 22.iso
/
bbs
/
pad321.zip
/
VERIFY.MH
< prev
next >
Wrap
Text File
|
1996-10-20
|
12KB
|
373 lines
#ifndef __VERIFY_MH
#define __VERIFY_MH
#ifndef __STRING_MH
#include "string.mh"
#endif
#ifndef __SETTINGS_MH
#include "settings.mh"
#endif
#ifndef __IN_MH
#include "in.mh"
#endif
#ifndef __FILE_MH
#include "file.mh"
#endif
#ifndef __HACKS_MH
#include "hacks.mh"
#endif
#ifndef __OUT_MH
#include "out.mh"
#endif
#ifndef __GENERAL_MH
#include "general.mh"
#endif
#include <rand.mh>
bool: hangupFlag;
void padlock_log (string: message) {
int: fd;
long: t;
struct _stamp: ts;
if (log_file = "") return;
if (fileexists (log_file)) {
fd := open (log_file,IOPEN_APPEND | IOPEN_WRITE);
}
else fd := open (log_file, IOPEN_CREATE | IOPEN_WRITE);
if (fd = -1) {
log (str_cant_open_log + log_file);
print (str_cant_open + log_file);
};
t := time ();
long_to_stamp (t,ts);
writeln (fd,stamp_string (ts) + " " + usr.name + " " + message);
close (fd);
}
int checkCodeWord (string: codeWord, string: message) {
int: passwordAttempts;
string: codeWordAttempt;
codeWord := strupper (codeWord);
for (passwordAttempts = 0; passwordAttempts < 3; passwordAttempts := passwordAttempts + 1) {
print (message);
input_str_ani (codeWordAttempt);
codeWordAttempt := strupper (codeWordAttempt);
if (codeWord = codeWordAttempt) return True;
print (str_bad_password_attempt + itostr (passwordAttempts+1)
+ str_bad_password_attempt_sfx);
};
vidsync ();
return False;
}
int checkPassword (string: codeWord, string: message) {
int: passwordAttempts;
string: codeWordAttempt;
codeWord := strupper (codeWord);
for (passwordAttempts = 0; passwordAttempts < 3; passwordAttempts := passwordAttempts + 1) {
input_str (codeWordAttempt, INPUT_NLB_LINE | INPUT_ECHO | INPUT_NOCTRLC, '.', 20, message + COL_CYAN);
codeWordAttempt := strupper (codeWordAttempt);
if (codeWord = codeWordAttempt) return True;
print (str_bad_password_attempt + itostr (passwordAttempts+1)
+ str_bad_password_attempt_sfx);
};
vidsync ();
return False;
}
// Dialout routines ----------------------------------------------------
// Dial calls the given phone number and returns the attempt's
// status. Constants returned by dial:
#define CONNECT 0
#define BUSY 1
#define NOCARRIER 2
#define NODIAL 3
#define VOICE 4
#define OTHER 5
#define TIMEOUT 6
#define USERABORT 7
#define DIFFERENTBAUD 8
int dial (string: phoneNum, int: waitTime) {
int: counter, responseIdx, tempIdx;
long: oldBaudrate;
char: key;
string: message, tempStr;
oldBaudrate := getBaudRate ();
flushInput (); // Flush input buffer
println_direct (scr_dialing + phoneNum);
mdm_command (mdm_dial_pfx + phoneNum // Perform dialout -
+ mdm_dial_sfx); // tell modem to dial
sleep (100); // Wait 1 second
flushInput (); // Flush input buffer
for (counter:=0;counter < waitTime; // Loop until timeout or modem returns message
counter := counter+ 1) { //
if (waitKey (100)) { // Wait 1 second
int: tmp; //
message := ""; // Initialize modem response string
do { // Handle all the data returned by the modem
key := getch (); // Get one character
if (localkey ()) { // If the sysop hit a key,
log (str_sysop_abort_log); // record to log file
println_direct (scr_sysop_abort); // Display local message
return USERABORT; // abort dialout
}; //
if (key >= 32) { // Don't add CR to the message string
tmp := strlen (message) + 1; // These two ugly lines append a char
message := strpad (message, tmp,key); // to the message string
}; //
sleep (10); // Wait for another char to arrive
} while (kbhit ()); // End loop if no more data waiting
println_direct (scr_modem_response + message);
log (str_modem_response_log + message); // Record modem response to log file
//
// Now, determine what message was returned
// by the modem and return appropriate result.
responseIdx := strfind (message, msg_connect);
if (responseIdx) {
responseIdx := responseIdx + strlen (msg_connect);
while ((message [responseIdx] = ' ') and (responseIdx < strlen (message)))
responseIdx := responseIdx + 1;
for (tempIdx := 1;(message [responseIdx] >= '0')
and (message [responseIdx] <= '9');responseIdx := responseIdx + 1) {
tempStr [tempIdx] := message [responseIdx];
tempIdx := tempIdx + 1;
};
if (oldBaudrate = strtol (tempStr)) return CONNECT;
return DIFFERENTBAUD;
};
if (strfind (message,msg_no_carrier)) return NOCARRIER;
if (strfind (message,msg_busy)) return BUSY;
if (strfind (message,msg_no_dialtone)) return NODIAL;
if (strfind (message,msg_voice)) return VOICE;
if (strfind (message,msg_ringing) = False) {
// Otherwise, unknown response.
log (str_unknown_message_log + message);// Record error
return OTHER; // Return error
}; //
}; //
} //
mdm_command ("|"); // Abort dialout
println_direct (scr_timeout);
log (str_connect_timeout_log); // Record timeout to logfile
return TIMEOUT; // return timeout
}
// Redial dials the given number until either the number of attempts
// is exceeded, VOICE or USERABORT is returned, or a successfull connect
// occours. Redial returns True if a successful connect occoured, and
// false otherwise. MaxAttempts is the maximum number of times the
// dialout should be attempted, and delay is the delay between each
// dialout attempt. WaitTime is the amount of time that max should
// wait for the remote system to pick up.
int redial (string: phoneNum, int: maxAttempts, int: delay,
int: waitTime) {
int: attempts, result, noDialRetry;
log (str_dialing_user_log);
for (attempts := 1;attempts <= maxAttempts; attempts := attempts + 1) {
println_direct (scr_verification_attempt + itostr (attempts));
log (str_dial_attempt_log + itostr (attempts));
result := dial (phoneNum, waitTime);
for (noDialRetry := 0; (noDialRetry < num_nodial_retries) and (result = NODIAL);
noDialRetry := noDialRetry + 1) {
sleep (num_nodial_retry_delay * 100);
log (str_nodial_retry_log);
result := dial (phoneNum, waitTime);
};
if (result = CONNECT) return True;
if (result = DIFFERENTBAUD) {
log (str_baudrate_changed_log);
if (num_baudrate_check_behaviour = 0) return True;
if ((num_baudrate_check_behaviour = 1)
or ((attempts = maxAttempts) and (num_baudrate_check_behaviour = 3))) {
show_file (bad_baudrate_file);
mdm_command (mdm_hangup);
return False;
};
if (num_baudrate_check_behaviour = 2) {
hangupFlag := True;
return True;
};
if (num_baudrate_check_behaviour = 3) {
show_file (bad_baudrate_attempt_file);
};
};
if ((result = USERABORT) or (result = VOICE)) return False;
println_direct (scr_waiting_attempt);
sleep (100*delay);
};
return False;
}
// callBack is the routine that actually performs the call back
// verification. It calls the given phone number and prompts the user
// for the code word. If the code word matches codeWord,
// then call back returns True.
int callBack (string: phoneNum, string: codeWord) {
int: connectStat;
string: codeWordAttempt, username;
int: passwordAttempts;
int: newPriv;
username := usr.alias;
if (username = "") username := usr.name;
#ifndef ALLOW_LOCAL
if (id.local <> 1) {
#endif
dcd_check (False);
print_direct (AVATAR_CLS);
println_direct (scr_verifying + usr.name);
println_direct (scr_any_key_to_abort);
mdm_command (mdm_hangup);
println_direct (scr_init_modem);
mdm_command (mdm_init);
connectStat := redial (phoneNum,num_attempts, num_delay,
num_connect_timeout);
if (connectStat = 0) log (str_fail_connect_log);
dcd_check (True);
if (connectStat = 0) return False;
#ifndef ALLOW_LOCAL
};
#endif
show (welcome_back_file, str_welcome_back1 + username + str_welcome_back2);
if (num_ask_codeword) {
print (str_welcome_back3);
if (checkCodeWord (codeWord, str_code_request) = False) {
show (bad_code_file, str_bad_code);
log (str_bad_code_log);
return False;
};
}
else print ("\n");
print ("\n");
if ((usr.encrypted = False) and (num_ask_password)) {
if (checkPassword (usr.pwd, str_pwd_request) = False) {
show (bad_password_file, str_bad_password);
log (str_bad_password_log);
return False;
};
};
return True;
}
#ifdef flg_use_codeword
string nonsenseWord () {
int: idx;
char: c;
string: s;
for (idx := 1; idx <= num_codeword_length; idx := idx + 1) {
c := rand ();
for (;c > 25; c := c - 26);
s [idx] := 'A' + c;
};
return s;
}
#endif
#ifndef flg_use_codeword
string nonsenseWord () {
int: idx;
char: c;
string: s;
for (idx := 1; idx <= num_codeword_length; idx := idx + 1) {
c := rand ();
for (;c > 9; c := c - 10);
s [idx] := '0' + c;
};
return s;
}
#endif
void verify (string: dialStr, string: newPhone, string: city, int: dialType) {
string: codeWord;
int: success;
seed := time ();
codeWord := nonsenseWord ();
show_file (help_file);
if (input_list_ani ("Yn\r", str_press_yn, str_proceed) = 'N') {
show_file (abort_file);
return;
};
if (num_ask_codeword) {
print (AVATAR_CLS);
print (str_tell_codeword + codeWord + "\n");
print (str_tell_codeword2);
print (COL_WHITE);
flushInput ();
menu_cmd (MNU_PRESS_ENTER, "");
};
print (str_hanging_up);
success := callBack (dialStr, codeWord);
if (success) {
int: newPriv;
usr.dataphone := newPhone;
if (num_update_city and (city <> ""))
usr.city := city;
log (str_user_verified_log);
newPriv := class_to_priv (str_new_sec);
if (usr.priv < newPriv)
usr.priv := newPriv;
usr.xkeys := usr.xkeys + str_new_keys;
stripStr (usr.xkeys,str_old_keys);
timeadjustsoft (num_time_bonus * 60);
padlock_log (newPhone + str_success_sfx_log);
show (success_file, str_success_message);
}
else {
log (str_fail_log);
padlock_log (newPhone + str_fail_sfx_log);
show (fail_file, str_fail_message);
};
if (dialType = DNLD) {
show_file (hangup_ld_file);
log (str_hangup_ld_log);
sleep (800);
mdm_command (mdm_hangup);
};
if (hangupFlag or num_always_hangup) {
show_file (success_hangup_file);
log (str_success_hangup_log);
sleep (1000);
mdm_command (mdm_hangup);
};
}
#endif